from apps.common.base.views import *
from apps.merchant.shop.serializers import *
from apps.merchant.shop.dao import ShopDao
from apps.merchant.shop.filters import ShopFilter
from apps.system.user.dao import UserDao


class BaseShopViewSet(BaseViewSet):
    serializer_class = ShopModelSerializer
    filter_class = ShopFilter
    DAO_CLASS = ShopDao

    @action(methods=['post'], detail=False)
    def getItemById(self, request):
        params = getRequestParams(self.request)
        obj_id = params.get('obj_id')
        if not obj_id:
            return Response(response_message('obj_id参数必填'))
        obj = self.DAO_CLASS().findOneByObjId(obj_id)
        # 增加销量
        obj.hots = F('hots') + 1
        obj.save()
        obj = self.DAO_CLASS().findOneByObjId(obj_id)
        model = self.serializer_class(obj).data
        return Response(response_success(model))